<!-- 蓝色登录页面2 -->
<template>
	<view class="total">
		<view class="img-a">
			<view class="header">
				<view class="return" style="opacity: 0;">
					<image style="width: 30px;height: 30px;margin-top: 10px;" src="/static/return.png" alt=""  />
				</view>
				<view class="" @click="toLogin2()">
					账号密码登录
				</view>
			</view>
		</view>
		<view class="login-view">
			<view class="t-login">
				<view class="welcome">
					欢迎登录候鸟养老商家端
				</view>
				<view class="log_style">
					<view class="blue_font">
						验证码登录
					</view>
					<view class="tishi">
						未注册手机验证通过后，将自动创建账号
					</view>
				</view>
				<form class="cl">
					<view class="t-a">
						<text class="txt">手机号码</text>
						<u-input class="codeInput" type="number" name="phone" placeholder="请输入您的手机号" maxlength="11" v-model="phone" />
					</view>
					<view class="t-a">
						<text class="txt">验证码</text>
						<u-input class="codeInput" placeholder="请输入验证码" v-model="code">
							<template slot="suffix">
								<u-code
								ref="uCode"
								@change="codeChange"
								:seconds="seconds"
								changeText="X秒">
								</u-code>
								<u-button
								id="getCodeButton"
								@tap="getCode"
								:text="tips"
								type="success"
								size="mini"
								>{{tips}}</u-button>
							</template>
						</u-input>
					</view>
					<view class="agreen">
						<view class="radios" @click="changeAgreen">
							<image style="width: 20px;height: 20px;" v-show="this.beAgreen" src="@/static/select.png" alt="" width="100%" height="100%">
							<image style="width: 20px;height: 20px;" v-show="!this.beAgreen" src="@/static/selected.png" alt="" width="100%" height="100%">
						</view>
						<view class="texts">
							阅读并同意<text class="txts" >《候鸟养老APP隐私政策》</text>与<text  class="txts">《候鸟养老APP用户协议》</text>
						</view>
					</view>
					<button class="login_button" v-if="beAgreen" style="background-color:#A8A8A8;">登 录</button>
					<button class="login_button" v-else @tap="login()">登 录</button>
				</form>
			</view>
		</view>
	</view>
</template>
<script>
import {login1} from "@/utils/api.js";
export default {
	data() {
		return {
			phone: '', //手机号码，
			code:'', //验证码
			password: '' ,//密码,
			password2:'',//确认密码
			beAgreen:true,
			tips: '发送验证码',
			seconds:60,
			firstTime:false,
			test:'',
			id:2,
			authForm:{
				orgName:'',
				startTime:'',
				orgCode:'',
				name:'',
				idNumber:'',
				tel:'',
				name2:'',
				idNumber2:'',
				tel2:''
			}
		};
	},
	onUnload(){
	         uni.$emit("getlist",{})//这里可以传个空,也可以传值过去
	},
	methods: {
		goBack(){
			if(this.firstTime){
				this.firstTime=false
			}else{
				uni.reLaunch({
					url:'/pages/my/my',
				})
			}
		},
		toLogin2(){
			uni.navigateTo({
				url:'/pages/login/login2',
				
			})
		},
		codeChange(text) {
			this.tips = text;
		},
		getCode() {
			var that =this
			if (!/^[1][3,4,5,6,7,8,9][0-9]{9}$/.test(that.phone)) {
				uni.showToast({ title: '请输入正确手机号', icon: 'none' });
				return;
			}
			if (this.$refs.uCode.canGetCode) {
				uni.request({
				    url: 'https://www.ghhlkj.com/api/sendSms',
				    data: {
				        phone:this.phone,
						type:1,	//1登陆所需验证码，2为修改密码所需验证码
				    },
					header:{
						'content-type':'application/json'
					},
					method:'POST',
				    success: (res) => {
				        console.log(res.data);
				    }
				});
			// 模拟向后端请求验证码
			uni.showLoading({
				title: '正在获取验证码'
			})
			setTimeout(() => {
				uni.hideLoading();
				// 这里此提示会被this.start()方法中的提示覆盖
				uni.$u.toast('验证码已发送');
				// 通知验证码组件内部开始倒计时
				this.$refs.uCode.start();
			}, 2000);
			} else {
				uni.$u.toast('倒计时结束后再发送');
			}
		},
		changeAgreen(){
			this.beAgreen=!this.beAgreen
		},
		
		//当前登录按钮操作
		login() {
			var that = this;
			if (!that.phone) {
				uni.showToast({ title: '请输入您的手机号', icon: 'none' });
				return;
			}
			if (!/^[1][3,4,5,6,7,8,9][0-9]{9}$/.test(that.phone)) {
				uni.showToast({ title: '请输入正确手机号', icon: 'none' });
				return;
			}
			if (!that.code) {
				uni.showToast({ title: '请输入您的验证码', icon: 'none' });
				return;
			}
			let data={
				admin_phone:this.phone,
				dxcodess:this.code
				}
			login1(data).then((res)=>{
				if(res.data.meta.status==200){
					uni.setStorageSync('phone',this.phone)
					uni.setStorageSync('user',res.data.data)
					if(res.data.data.length===0){
						uni.showToast({
							title:'第一次登录，请进行机构认证',
							icon:'none'
						})
						setTimeout(()=>{
							uni.navigateTo({
								url:'/pages/login/auth'
							})
						},1000)
					}else{
						uni.showToast({
							title:'登陆成功！',
							icon:'none'
						})
						setTimeout(()=>{
							uni.switchTab({
								url:'/pages/my/my'
							})
						},1000)
					}
				}
				else{
					uni.showToast({
						title:res.data.meta.msg,
						icon:'none'
					})
				}
			})
		},
	},
	}
</script>
<style lang="scss" scoped>
.total{
	background-color: #f6f6f6;
	height: 100%;
	position: relative;
}
.txt {
	font-size: 32rpx;
	font-weight: bold;
	color: #333333;
}
.img-a {
	background-image: url('/static/img/login_img_bgs.png');
	padding-top: 20px;
	width: 100%;
	height: 450rpx;
	background-repeat: no-repeat;
	background-size: 100%;
	.header{
		height: 50px;
		line-height: 50px;
		font-size: 20px;
		font-weight: 400;
		color: #FFFFFF;
		display: flex;
		justify-content: space-between;
		padding: 0px 20px;
		.return{
			width: 30px;
			height: 30px;
			line-height: 30px;
			// font-size: 5px;
			// display: flex;
			// justify-content: center;
			// align-items: center;
		}
	}
}
.reg {
	font-size: 28rpx;
	color: #fff;
	height: 90rpx;
	line-height: 90rpx;
	border-radius: 50rpx;
	font-weight: bold;
	background: #f5f6fa;
	color: #000000;
	text-align: center;
	margin-top: 30rpx;
}

.login-view {
	background: #FFFFFF;
	border-radius: 5px;
	width: 94%;
	height: 600px;
	margin: auto;
	top: 0px;
	left: 0;
	right: 0;
	bottom: 0;
	margin-top: -150px;
	
}

.t-login {
	width: 600rpx;
	margin: 0 auto;
	font-size: 28rpx;
	padding-top: 80rpx;
	.welcome{
		color:#242424;
		font-size: 25px;
		font-weight: bolder;
	}
	.log_style{
		margin-top: 25px;
		.blue_font{
			color: #2796f2;
			font-size: 18px;
			font-family: PingFang SC;
			font-weight: 800;
		}
		.tishi{
			margin-top: 10px;
			margin-bottom: 50px;
			font-size: 12px;
			font-family: PingFang SC;
			font-weight: 500;
			color: #868686;
		}
	}
	#getCodeButton{
		width: 80px;
		background-color: #2796f2;
		border-color: #2796f2;
		border-radius: 24px;
		height: 28px;
	}
	.codeInput{
		height: 33px;
		line-height: 90rpx;
		margin-top: 30rpx;
		margin-bottom: 50rpx;
		border: 1px solid #e9e9e9;
		border-radius: 8px;
		background-color: #F6F6F6;
		font-size: 28rpx;
		padding: 0 15px;
	}
}

.t-login .login_button {
	margin-top: 20px;
	font-size: 35rpx;
	background: #2796f2;
	color: #fff;
	height: 90rpx;
	width: 250px;
	line-height: 90rpx;
	border-radius: 50rpx;
	font-weight: bold;
}
.t-login .t-a {
	position: relative;
}

.t-b {
	text-align: left;
	font-size: 42rpx;
	color: #ffffff;
	padding: 130rpx 0 0 70rpx;
	font-weight: bold;
	line-height: 70rpx;
}

.t-login .t-c {
	position: absolute;
	right: 22rpx;
	top: 22rpx;
	background: #5677fc;
	color: #fff;
	font-size: 24rpx;
	border-radius: 50rpx;
	height: 50rpx;
	line-height: 50rpx;
	padding: 0 25rpx;
}

.t-login .t-d {
	text-align: center;
	color: #999;
	margin: 80rpx 0;
}

.t-login .t-e {
	text-align: center;
	width: 250rpx;
	margin: 80rpx auto 0;
}

.t-login .t-g {
	float: left;
	width: 50%;
}

.t-login .t-e image {
	width: 50rpx;
	height: 50rpx;
}

.t-login .t-f {
	text-align: center;
	margin: 150rpx 0 0 0;
	color: #666;
}

.t-login .t-f text {
	margin-left: 20rpx;
	color: #aaaaaa;
	font-size: 27rpx;
}

.t-login .uni-input-placeholder {
	color: #aeaeae;
}

.cl {
	zoom: 1;
	.agreen{
		display: flex;
			.radios{
				width: 28px;
				height: 20px;
				margin-right:10px ;
			}
			.texts{
				.txts{
					color:#5398F6;
				}
			}
		
	}
}

.cl:after {
	clear: both;
	display: block;
	visibility: hidden;
	height: 0;
	content: '\20';
}
</style>
